package com.mjlf.hometeach.common.db.provider.assit;

import com.mjlf.hometeach.common.entity.assit.Grade;
import org.apache.ibatis.jdbc.SQL;

/**
 * @auther a123
 * @create 2018-05-05 17:29
 * @desc 年级动态sql
 */
public class GradeProvider {

    /**
     * 添加年级信息到数据库
     * @param grade
     * @return
     */
    public String save(Grade grade){
        SQL sql = new SQL();

        if(grade != null){
            sql.INSERT_INTO("grade_tbl");
            if(grade.getName() != null){
                sql.VALUES("name", "#{name}");
            }
            if(grade.getCreateTime() != null){
                sql.VALUES("create_time", "#{createTime}");
            }
            if(grade.getModifyTime() != null){
                sql.VALUES("modify_time", "#{modifyTime}");
            }
        }
        return sql.toString();
    }

    /**
     * 根据id删除指定的年级信息
     * @return
     */
    public String deleteById(){
        SQL sql = new SQL();

        sql.DELETE_FROM("grade_tbl").WHERE("id = #{id}");
        return sql.toString();
    }

    /**
     * 查询所有的年级信息
     * @return
     */
    public String listAllGrade(){
        SQL sql = new SQL();

        sql.SELECT("id")
                .SELECT("name")
                .SELECT("create_time AS createTime")
                .SELECT("modify_time AS modifyTime")
                .FROM("grade_tbl");
        return sql.toString();
    }
}
